<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>岗位详情</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" href="../../common/css/bootstrap.css" type="text/css">
        <link href="../../common/css/nice-select.css" rel="stylesheet">
        <link href="../../common/css/style.css" rel="stylesheet">
        <link rel="stylesheet" href="../../common/css/layui.css">
        <script src="../js/jquery-3.6.0.js"></script>
        <script src="../js/bootstrap.js"></script>
        <script src="../js/commons.js"></script>
        <script src="../../common/js/layui.js"></script>
        <style type="text/css">
            @font-face {
                font-family: 'FontAwesome';
                src: url('https://netdna.bootstrapcdn.com/font-awesome/3.2.1/font/fontawesome-webfont.woff?v=3.2.1') format('woff');
            }

            body {
                background-color: #F2F4F7;
            }

            .all {
                width: 70%;
                margin: 20px auto;
                background-color: #FFFFFF;
                border-radius: 10px;
                padding: 20px;
            }

            .title {
                font-weight: 700;
                font-size: 15px;
                color: #424a5e;
                margin: 15px 0;
            }

            .content {
                color: #51586d;
                font-size: 16px;
                margin: 15px 0 15px 50px;
            }

            .job {
                /*margin-left: 300px;*/
            }

            .company .title {
                font-size: 16px;
            }

            .company .content {
                font-size: 14px;
            }

            .recruit {
                /*margin-left: 300px;*/
            }

            .jname {
                font-size: 40px;
                height: 33px;
                line-height: 33px;
                display: inline-block;
                vertical-align: baseline;
                margin-bottom: 20px;
            }

            .collect {
                font-size: 16px;
                height: 33px;
                width: 100px;
                line-height: 33px;
                margin-left: 20px;
                background-color: #6ADBCF;
                border-radius: 5px;
                border: none;
                display: inline-block;
                vertical-align: top;
            }

            .head {
                width: auto;
                height: 60px;
                border: 1px solid cadetblue;
                text-align: right;
            }

            .head1 {
                border-radius: 90px;
                font-size: 20px;
                border: 1px cadetblue solid;
                text-align: right;
            }

            .one_br {
                width: 100%;
                margin: 20px auto;
                height: 2px;
                background-color: rgb(237, 240, 245, 1);
            }
        </style>
    </head>
    <body>
        <div class="head">
            <ul class="layui-nav layui-bg-green">
                <li class="layui-nav-item"><a href="main.html">首页</a></li>
                <li class="layui-nav-item"><a href="defaultJob.html">职位</a></li>
                <li class="layui-nav-item"><a href="../../common/html/resume.html">简历</a></li>
                <li class="layui-nav-item" onclick="chat()">
                    <a href="javascript:;">消息</a>
                </li>
                <li class="layui-nav-item">
                    <div style="margin-left: 5px; cursor: pointer">
                        <span class="head1 state" id="aa" onclick="login()">登录</span>
                        <span class="head1 state1" id="aaa" onclick="toUserPage()" style="display: none"></span>
                    </div>
                </li>
            </ul>
        </div>
        <div class="all">
            <div class="job">
                <span hidden id="jid"></span>
                
                <div id="jname" class="jname">岗位名称</div>
                <button id="collectStatus" class="collect" onclick="collectJob()">岗位收藏</button>
                <button class="collect" onclick="chatHR()">立即沟通</button>
                <div class="title">工作地址</div>
                <div id="address" class="address content"></div>
                <div class="title">薪资</div>
                <div id="salary" class="salary content"></div>
                <div class="title">岗位描述</div>
                <div id="description" class="description content"></div>
                <div class="title">岗位要素</div>
                <div id="point" class="point content"></div>
            </div>
            <div class="one_br"></div>
            <div class="recruit">
                <div class="title">招聘者</div>
                <div class="hrName content" id="hrName"></div>
            </div>
            <div class="one_br"></div>
            <div class="company">
                <div class="title">公司名</div>
                <div id="cname" class="cname content"></div>
                <div class="title">公司法人</div>
                <div id="legal" class="legal content"></div>
                <div class="title">公司地址</div>
                <div id="cAddress" class="cAddress content"></div>
            </div>
        </div>
        
        <script>
            var INDEX = "http://localhost:8080/recruit/";
            let activeUser;
            $.ajax({
                url: INDEX + "user/info",
                headers: {"token": localStorage.getItem("token")},
                success: function (result) {
                    if (result.code == 0) {
                        activeUser = result.data;
                        if (activeUser == null) {
                            $(".state1").css("display", "none");

                        } else {
                            $(".state").css("display", "none");
                            $(".state1").css("display", "block");
                            $(".state1").text(activeUser.nickname == null ? activeUser.username : activeUser.nickname);
                        }
                    }
                }
            })

            var layer = layui.layer;

            var jobData = JSON.parse(sessionStorage.getItem("job"));
            var job = jobData.jobVo;
            var company = jobData.company;
            var hr = jobData.recruiter;
            var hrId = hr.uid;
            var cid = company.cid;
            var jid = job.jid;

            getData();
            changeStatus();

            function getData() {
                $("#jid").val(job.jid);
                $("#jname").text(job.jname);
                $("#address").text(job.workAddress);
                $("#salary").text(job.minSalary + "-" + job.maxSalary);
                $("#description").text(job.description);
                $("#point").text(job.requirement);
                $("#cname").text(job.companyName);
                $("#type").text(job.type);
                $("#collectStatus").val(job.collectState);
                $("#hrName").text(hr.nickname);
                $("#photo").text(hr.photo);
                $("#cname").text(company.cname);
                $("#legal").text(company.legalPerson);
                $("#cAddress").text(company.address);
            }

            function collectJob() {
                var collectStatus = $("#collectStatus").val();
                var jid = $("#jid").val();
                $.ajax({
                    url: URL + "seeker/job/collect?jid=" + jid + "&state=" + collectStatus,
                    data: {},
                    headers: {"token": localStorage.getItem("token")},
                    type: "get",
                    success: function (result) {
                        if (result.code == 0) {
                            alert("操作成功");
                            changeStatus();
                        } else if (result.code == 1) {
                            alert("操作是失败");
                        } else {
                            window.location.href = "../../common/html/login.html";
                        }

                    }
                })
                detail(jid);
            }

            function changeStatus() {
                var collectStatus = $("#collectStatus").val();
                if (collectStatus === '0') {
                    $("#collectStatus").text("取消收藏");
                    $("#collectStatus").val("1");
                } else {
                    $("#collectStatus").text("点击收藏");
                    $("#collectStatus").val("0");
                }
            }

            function detail(jid) {
                $.ajax({
                    url: URL + "seeker/job/detail?jid=" + jid,
                    data: {},
                    type: "get",
                    success: function (result) {
                        if (result.code == 0) {
                            sessionStorage.setItem("job", JSON.stringify(result.data));
                        }
                    }
                })
            }

            function chatHR() {
                localStorage.setItem("hrId", hrId);
                localStorage.setItem("cid", cid);
                localStorage.setItem("jid", jid);
                window.location.href = "package/html/chat.html";
            }

            function login() {
                window.location.href = "../../common/html/login.html";
                window.event.returnValue = false;
            }

            function chatHR() {
                localStorage.setItem("hrId", hrId);
                localStorage.setItem("cid", cid);
                localStorage.setItem("jid", jid);
                window.location.href = "package/html/chat.html";
            }

            //默认岗位页
            function defaultJob() {
                window.location = "defaultJob.html";
            }

            function login() {
                window.location.href = "../../common/html/login.html";
                window.event.returnValue = false;
            }


            function chat() {
                window.location.href = "package/html/chat.html";
            }

            function toUserPage() {
                window.location.href = "seekers.html";
            }
        </script>
    
    </body>
</html>